package com.yang.springcloudalibaba.controller;

import com.alibaba.fastjson.JSONObject;
import com.yang.springcloud.pojo.Menu;
import com.yang.springcloudalibaba.service.MenuServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class MenuController {

    @Autowired
    MenuServiceImp menuServiceImp;

    @PostMapping("/queryMenu")
    public Map<String, Object> queryMenu(@RequestParam(name = "menuid") int menuid) {
        return menuServiceImp.queryMenu(menuid);
    }

    @PostMapping("/queryRoleMenu")
    public Map<String, Object> queryRoleMenu(@RequestParam(name = "menuid") int menuid, @RequestParam(name = "roleid") int roleid) {
        return menuServiceImp.queryRoleMenu(menuid, roleid);
    }

    @PostMapping("/insertRoleMenu")
    public Map<String, Object> queryRoleMenu(@RequestParam(name = "roleid") int roleid, @RequestParam(name = "menu") String menuStr) {
        Menu menu = JSONObject.parseObject(menuStr, Menu.class);
        return menuServiceImp.insertRoleMenu(roleid, menu);
    }

    @PostMapping("/queryRoleMenuAsync")
    public Map<String, Object> queryRoleMenuAsync(@RequestParam(name = "menuid") int menuid, @RequestParam(name = "roleid") int roleid) throws InterruptedException {
        return menuServiceImp.queryRoleMenuAsync(menuid, roleid);
    }

    @PostMapping("/insertRoleMenuAsync")
    public Map<String, Object> queryRoleMenuAsync(@RequestParam(name = "roleid") int roleid, @RequestParam(name = "menu") String menuStr) throws InterruptedException {
        Menu menu = JSONObject.parseObject(menuStr, Menu.class);
        return menuServiceImp.insertRoleMenuAsync(roleid, menu);
    }
}
